class CreateUsers < ActiveRecord::Migration
  def self.up

    create_table :users do |t|
      t.column :first_name, :string
      t.column :last_name, :string
      t.column :phone_number, :string
      t.column :email_address, :string
      t.column :login, :string
      t.column :crypted_password, :string
      t.column :password_salt, :string
      t.column :persistence_token, :string
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
    end

    create_table :permissions do |t|
      t.column "controller", :string, :default => "", :null => false
      t.column "action", :string, :default => "", :null => false
      t.column "description", :string
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
    end

    create_table :roles do |t|
      t.column "name", :string, :default => "", :null => false
      t.column "description", :string
      t.column "omnipotent", :boolean, :default => false, :null => false
      t.column "system_role", :boolean, :detault => false
      t.column :created_at, :datetime
      t.column :updated_at, :datetime
    end

    create_table :permissions_roles, :id => false do |t|
      t.column "permission_id", :integer, :default => 0, :null => false
      t.column "role_id", :integer, :default => 0, :null => false
    end

    create_table :roles_users, :id => false do |t|
      t.column "user_id", :integer, :default => 0, :null => false
      t.column "role_id", :integer, :default => 0, :null => false
    end



    User.create :first_name => 'Dominik',
                :last_name => 'Kunicki',
                :email_address => 'dominik@wp.pl',
                :phone_number => '678894784',
                :login => 'admin',
                :password =>'admin',
                :password_confirmation =>'admin'

    User.create :first_name => 'Jakub',
                :last_name => 'Technik',
                :email_address => 'jakub@wp.pl',
                :phone_number => '458894784',
                :login => 'jakub',
                :password =>'jakub',
                :password_confirmation =>'jakub'

    User.create :first_name => 'Wacek',
                :last_name => 'Bogucki',
                :email_address => 'jan@wp.pl',
                :phone_number => '958894784',
                :login => 'wacek',
                :password =>'wacek',
                :password_confirmation =>'wacek'

    User.create :first_name => 'Pawel',
                :last_name => 'Nastula',
                :email_address => 'pawel@wp.pl',
                :phone_number => '798894784',
                :login => 'pawel',
                :password =>'pawel',
                :password_confirmation =>'pawel'

    

    Role.create :name => 'Kierownik',
                :description => 'Zarządza systemem',
                :omnipotent => true,
                :system_role => true

    Role.create :name => 'Recepcjonista',
                :description => 'Zarządza recepcja',
                :omnipotent => true,
                :system_role => true

    Role.create :name => 'Technik',
                :description => 'Zarządza badaniami',
                :omnipotent => true,
                :system_role => true

    Role.create :name => 'Diagnosta Labolatoryjny',
                :description => 'Zatwierdzanie wyników',
                :omnipotent => true,
                :system_role => true

    Role.create :name => 'Pielegniarka',
                :description => 'Pracownia pobrań',
                :omnipotent => true,
                :system_role => true


    execute <<-SQL
      INSERT INTO roles_users VALUE (1, 1)
    SQL

    execute <<-SQL
      INSERT INTO roles_users VALUE (2, 2)
    SQL

    execute <<-SQL
      INSERT INTO roles_users VALUE (3, 3)
    SQL
     execute <<-SQL
      INSERT INTO roles_users VALUE (4, 4)
    SQL
  end


  def self.down
    drop_table :permissions_roles
    drop_table :roles_users
    drop_table :permissions
    drop_table :roles
    drop_table :users
  end

end
